package com.sinodata.bsm.cicp.finder.linux;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.sinodata.bsm.cicp.util.CommandReader;

public class LinuxFDisk extends LinuxFinder {
    private static final Logger logger = Logger.getLogger(LinuxFDisk.class);
    private static final String CMDSTR = "iostat -d|sed -e '1,3d'|awk '{print $1}'";

    @Override
    public List<String[]> find(String ip, Map params) {
        List<String[]> list = new ArrayList<String[]>();
        String strLine = null;
        String[] fdiskInfo = null;
        BufferedReader reader = null;
        try {
            reader = CommandReader.getReader(ip, CMDSTR, 0, 0);
            while ((strLine = reader.readLine()) != null && !strLine.trim().equals("")) {
                strLine = strLine.trim();
                fdiskInfo = new String[4];
                list.add(fdiskInfo);
                fdiskInfo[0] = strLine;
                fdiskInfo[1] = strLine;
                fdiskInfo[2] = getHostName(ip) + " Disk " + strLine;
                fdiskInfo[3] = strLine;//盘符
            }
        } catch (IOException e) {
            logger.error("failed to find linux FDisk", e);
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    logger.error("failed to close reader", e);
                }
            }
        }
        return list;
    }

}
